﻿//-----------------------------------------------------------------------
// <copyright file="Program.cs" company="DylanBox">
// Copyright (c) DylanBox Corporation. All rights reserved.
// </copyright>
// <summary></summary>
// <reference>
//    http://www.codeproject.com/KB/aspnet/Exception_FrameWork.aspx
//    
//    This project combine custome exception and enterprise library.
//    This project aslo use MVP architecture http://www.codeproject.com/KB/architecture/MVP.aspx

// </reference>
// <author>Dylan</author>
//-----------------------------------------------------------------------
using System;
using Project.Practice.MVP.ExceptionHandling;
using Project.Practice.MVP.ExceptionHandling.CustomException;
using Project.Practice.MVP.Framework;
using Project.Practice.MVP.Presenter;

namespace Project.Practice.MVP.WebSite
{
    public partial class Calculations : CustomPage, ICalculationView
    {
        #region Private Members
        private CalculationPresenter m_Presenter = null;
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                m_Presenter = new CalculationPresenter((ICalculationView)this);
                if (ViewState["USER_KEY_VALUE"] == null)
                {
                    throw new ViewLayerException("Code Behind Exception");
                }
            }
            catch (Exception ex)
            {
                if (ExceptionHandleProvider.HandleException(ex, "Global Policy") == true)
                {
                    throw ex;
                }
            } 
        }

        #region ICalculationView Members

        int ICalculationView.Numbers1
        {
            get 
            {
                return Convert.ToInt32(txtNumber1.Text);
            }
        }

        int ICalculationView.Numbers2
        {
            get 
            {
                return Convert.ToInt32(txtNumber2.Text);
            }
        }

        string ICalculationView.Result
        {
            set 
            {
                lblResult.Text = value;
            }
        }

        #endregion

        public override string Error
        {
            set
            {
                pnlError.Visible = true;
                lblException.Text = value;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                m_Presenter.AddNumbers();
            }
            catch (Exception ex)
            {
                if (ExceptionHandleProvider.HandleException(ex, "Global Policy") == true)
                {
                    throw ex;
                }
            } 
        }
    }
}
